package br.com.hotel68.view.gui.model;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.table.AbstractTableModel;

import br.com.hotel68.model.Room;

public class RoomTableModel extends AbstractTableModel {

	ArrayList<Room> rooms;

	// the headers
	String[] header;


	public RoomTableModel(Collection<Room> rooms) {
		
		this.header = new String[]{"Quarto Nº","Tipo","Preço"};		
		
		this.rooms = new ArrayList<Room>();
		this.rooms.addAll(rooms);
		
		
	}
	

	// method that needs to be overload. The row count is the size of the ArrayList
	public int getRowCount() {

		return rooms.size();

	}

	// method that needs to be overload. The column count is the size of our header
	public int getColumnCount() {

		return header.length;

	}

	// method that needs to be overload. The object is in the arrayList at rowIndex
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return rooms.get(rowIndex).getName();
		case 1:
			return rooms.get(rowIndex).getType().getDescription();
		case 2:
			return rooms.get(rowIndex).getType().getValue();
		default:
			return "0";
		}
	}

	// a method to return the column name
	public String getColumnName(int index) {

		return header[index];

	}

	// a method to add a new line to the table
	void add(Room room) {
		
		rooms.add(room);
		fireTableDataChanged();
		
	}
}
